#include<bits/stdc++.h>
using namespace std;
int d[100005],s[100005],a[100005],b[100005];
struct node{
    int l,r;
};
bool cmp(node x,node y){
    if(x.l==y.l)return x.r<y.r;
    return x.l>y.l;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        vector<node>c;
        int n,m,l,v,ans=0,cnt=1;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++)cin>>d[i]>>s[i]>>a[i];
        for(int i=1;i<=m;i++)cin>>b[i];
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(s[i]<=v)continue;
                int x=lower_bound(b+1,b+1+m,d[i])-b;
                if(x<=m){
                    c.push_back({x,m});
                    ans++;
                    //cout<<i<<" ";
                }
            }
            else if(a[i]>0){
                double x=d[i];
                if(s[i]<v){
                    x=d[i]+v*v-s[i]*s[i]/2.0/a[i];
                    int y=upper_bound(b+1,b+1+n,x)-b;
                    if(y<=m){
                        c.push_back({y,m});
                        ans++;
                        //cout<<i<<" ";
                    }
                }
                else{
                    int y=lower_bound(b+1,b+1+n,x)-b;
                    if(y<=m){
                        c.push_back({y,m});
                        ans++;
                    }
                }
            }
            else{
                if(s[i]<=v)continue;
                double x=d[i]+(v*v-s[i]*s[i])/2.0/a[i];
                int y=lower_bound(b+1,b+1+n,d[i])-b,z=upper_bound(b+1,b+1+n,x)-b;
                //cout<<x<<" "<<y<<" "<<z<<endl;
                if(y<=m && b[y]*1.0-x<0){
                    c.push_back({y,z});
                    ans++;
                    //cout<<i<<" ";
                }
            }
        }
        cout<<ans<<" ";
        sort(c.begin(),c.end(),cmp);
        int L=c[0].l,R=c[0].r;
        for(int i=1;i<c.size();i++){
            //cout<<c[i].l<<" "<<c[i].r<<endl;
            if(c[i].r<=L || c[i].l>=R){
                cnt++;
                L=c[i].l;
                R=c[i].r;
            }
        }
        cout<<m-cnt<<endl;
    }
    return 0;
}
